package com.gupao.gupaoeduvippattern.javaBase.thread.day01.test2;

/**
 * @author Administrator
 * @date 2020-12-04 16:50
 */
public class SleepDemo {

    public static void main(String[] args) {
        MyThread mt1 = new MyThread();
        Thread t1 = new Thread(mt1);
        t1.start();
        t1.start();

//        Thread t2 = new Thread(mt1);
//        t2.start();


    }


}

class MyThread implements Runnable{

    /**
     * When an object implementing interface <code>Runnable</code> is used
     * to create a thread, starting the thread causes the object's
     * <code>run</code> method to be called in that separately executing
     * thread.
     * <p>
     * The general contract of the method <code>run</code> is that it may
     * take any action whatsoever.
     *
     * @see Thread#run()
     */
    @Override
    public void run() {
        for(int i=1; i<=10; i++){
            System.out.println(Thread.currentThread() + ":开始运行" + i);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

